package controller;

import domain.Student;
import org.junit.Test;
import service.StudentService;
import service.impl.StudentServiceImpl;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    private StudentService service = new StudentServiceImpl();

    /**
     * 查询所有
     */
    @Test
    public void findAll() {
        ArrayList<Student> students = service.findAll();
        for (Student student : students) {
            System.out.println(student);
        }
    }

    ;

    /**
     * 根据ID查询
     */
    @Test
    public void findById() {
        int id = 1;
        Student student = service.findById(id);
        System.out.println(student);

    }

    ;

    /**
     * 增加信息
     */
    @Test
    public void insert() {
        Student stu = new Student(6, "张三", 77, new Date());
        int result = service.insert(stu);
        if (result != 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    ;

    /**
     * 删除信息
     */
    @Test
    public void delete() {
        int result = service.delete(2);
        if (result != 0) {
            System.out.println("删除成功！");
        } else {
            System.out.println("删除失败！");
        }
    }

    ;

    /**
     * 修改信息
     */
    @Test
    public void update() {
        Student student = new Student(1, "林更新", 23, new Date());
        int result = service.update(student);
        if (result != 0) {
            System.out.println("修改成功！");
        } else {
            System.out.println("修改失败！");
        }
    }

    ;
}
